package com.my.chapter11;

import java.util.*;

public class practice21 {
    private static Map<String,Integer> map = new HashMap<String,Integer>();

    static void countWords(String[] s){
        for(String str:s){
            if(map.containsKey(str)){
                Integer count = map.get(str);
                map.put(str,++count);
            }else{
                map.put(str,1);
            }
        }
    }


    public static void main(String[] args) {
        String s = "A contented mind is the greatest blessing a man can enjoy in this world";
        String[] str = s.split(" ");
        countWords(str);
        System.out.println(map);
        List<String> keyList = new ArrayList<>(map.keySet());
        Collections.sort(keyList,String.CASE_INSENSITIVE_ORDER);
        for(String key : keyList){
            System.out.println(key + "：" + map.get(key));
        }
    }
}
